﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevTeam;
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Depo
{
    public partial class AyrimEdit : XForm
    {
        string AyrimIds;
        public AyrimEdit(string ayrimIds)
        {
            InitializeComponent();
            AyrimIds = ayrimIds;
        }

        private void AyrimEdit_Load(object sender, EventArgs e)
        {
            
            gridView1.Init("GetAyrimEdit", AyrimIds);
            gridView1.MakeColumnInvisible("AyrimId", "idx");
            gridView1.YanYanaGetir("OrderRef:BrandId");
            gridView1.BestFitColumns();

            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gridView1.ShowingEditor += gridView1_ShowingEditor;
            gridView1.OptionsView.EnableAppearanceEvenRow = false;
            gridView1.RowStyle += gridView1_RowStyle;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DataTable dt = ExecuteDataTable("UpdAyrim", gridView1.Serialize(),
               (int)gridView1.GetFocusedRowCellValue("idx"), WhoAmI);

            if (dt.Rows.Count > 0)
                XtraMessageBox.Show(dt.Rows[0][0].ToString(), "Hata");
            else
                DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (e.RowHandle == gridView1.FocusedRowHandle)
                e.Appearance.BackColor = Color.YellowGreen;
        }

        void gridView1_ShowingEditor(object sender, CancelEventArgs e)
        {
            e.Cancel = (int)gridView1.GetFocusedRowCellValue("idx") > 0;
        }

      
    }
}
